package com.csnf.service.impl;

import com.csnf.feing.AccountFeigClient;
import com.csnf.mapper.OrderMapper;
import com.csnf.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderImplService implements OrderService {

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    AccountFeigClient accountFeigClient;

    @Override
    public int addOrder(String userId, String productCode, int count) {

        //正常的逻辑，应该是请求商品服务，获取商品的单价
        int money = 8 * count ;

        //调用远程服务，进行扣款
        accountFeigClient.reduceAccount(userId, money);

        return orderMapper.addOrder(userId, productCode, count, money);
    }
}
